/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.domain.analysis.results;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 *
 * @author user
 */
public class ParameterCoord implements Serializable, Cloneable {

    /**
     *
     */
    private static final long serialVersionUID = 4285048496471390345L;
    private BigDecimal xCoord = BigDecimal.ZERO;
    private BigDecimal yCoord = BigDecimal.ZERO;

    /**
     * 
     */
    public ParameterCoord() {
    	super();
    }

    /**
     * 
     * @param x
     * @param y
     */
    public ParameterCoord(BigDecimal x, BigDecimal y) {
        this.xCoord = x;
        this.yCoord = y;
    }

    /**
     * @return the xCoord
     */
    public BigDecimal getxCoord() {
        return this.xCoord;
    }

    /**
     * @param xCoord the xCoord to set
     */
    public void setxCoord(BigDecimal xCoord) {
        this.xCoord = xCoord;
    }

    /**
     * @return the yCoord
     */
    public BigDecimal getyCoord() {
        return this.yCoord;
    }

    /**
     * @param yCoord the yCoord to set
     */
    public void setyCoord(BigDecimal yCoord) {
        this.yCoord = yCoord;
    }

    /**
     * @return point x as string
     */
    public String getXasString() {
        return this.coordAsString(this.xCoord);
    }

    /**
     * @return point  as string
     */
    public String getYasString() {
        return this.coordAsString(this.yCoord);
    }

    private String coordAsString(BigDecimal value) {
        if (value == null) {
            return "0";
        }
        DecimalFormat pattern = new DecimalFormat("###.00");
        return pattern.format(value);
    }

    @Override
    public Object clone() throws CloneNotSupportedException {

        ParameterCoord copyCoord = null;

        try {
            copyCoord = (ParameterCoord) super.clone();
            copyCoord.setxCoord((new BigDecimal((this.getxCoord()!=null)?this.getxCoord().floatValue():0.0)));
            copyCoord.setyCoord((new BigDecimal((this.getyCoord()!=null)?this.getyCoord().floatValue():0.0)));
        } catch (CloneNotSupportedException ex) {
            ex.printStackTrace();
        }
        return copyCoord;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ParameterCoord other = (ParameterCoord) obj;
        if (this.xCoord != other.xCoord && (this.xCoord == null || !this.xCoord.equals(other.xCoord))) {
            return false;
        }
        if (this.yCoord != other.yCoord && (this.yCoord == null || !this.yCoord.equals(other.yCoord))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (this.xCoord != null ? this.xCoord.hashCode() : 0);
        hash = 31 * hash + (this.yCoord != null ? this.yCoord.hashCode() : 0);
        return hash;
    }

    
}
